<!--
 * Date: 2018年01月02日 09:32:33
 * LastEditors  : lvyou
 * LastEditTime : 2020年01月15日 14:20:34
 * FilePath: \youlinweb-master\src\components\allhot-header.vue
 * copyright(c) 2019-2025 版权为浙江双城网络科技集团有限公司所有，违者必究。
 -->
<template>
  <div class="hot-header" @click="godetail($event,topicindex,commentindex,tabId)">
     <div class="pendant-container">
      <img class="avatar" v-lazy="avatarimg" />
      <img :src="pendantPicUrl"  class="pendant" v-if="pendantType!=0&&pendantPicUrl">
      <img src="https://youlingqinius.wonderlandnet.cn/youlin-shengdan@2x.png"  class="pendant" v-else-if="pendantType==1">
      <img src="https://youlingqinius.wonderlandnet.cn/youlin-yuandan@2x.png"  class="pendant" v-else-if="pendantType==2">
      <img src="https://youlingqinius.wonderlandnet.cn/youlin-chunjie@2x.png"  class="pendant" v-else-if="pendantType==3">
      <img src="https://youlingqinius.wonderlandnet.cn/youlin-yuanxiao@2x.png"  class="pendant" v-else-if="pendantType==4">
      <img src="~img/vip.png"  class="vipimg v-h" v-else-if="userType==2">
      <img src="~img/daren.png"  class="vipimg v-h" v-else-if="isTalent==1">
     </div>
    <div class="header-right">
      <div class="nameleft">
        <span class="name">{{nickname}}</span>
        <span class="hot-shuoshuo-time" v-if="discuessTime">{{showtime(saytime)}}</span>
        <span class="hot-shuoshuo-time" v-else>{{saytime}}</span>
      </div>
      <div class="discusstime">
        <span class="hot-discuss-time" v-if="type==0&&floor!=null">{{floor}}楼</span>
        <span class="hot-discuss-time" v-if="type==0">{{topictime}}</span>
        <div class="hot-shuoshuo" v-if="type==1">
          <span class="yl-2map" style="font-size: 0.3rem;margin-right: 0.1rem">  </span>
          <span>{{place}}</span>
        </div>
      </div>

    </div>
    <span class="yl-tuijian ss-tui" v-if="ssshow"></span>
  </div>
</template>
<script >
  export default{
    data (){
      return {
      }
    },
    props:['discuessTime','type','avatarimg','nickname','topictime','commentindex','topicindex','place','saytime','floor','tabId','ssshow','userType','isTalent',"pendantType",'pendantPicUrl'],
    //ssshow:说说是否人工推荐
    methods:{
      godetail(event,topicindex,commentindex,tabId){
        this.$emit("topiccommentdetail",{event:event,topicindex:topicindex,commentindex:commentindex,tabId:tabId})

      },
      showtime(time) {
        let date =
          typeof time === "number"
            ? new Date(time)
            : new Date((time || "").replace(/-/g, "/"));
        let diff = (new Date().getTime() - date.getTime()) / 1000;
        let dayDiff = Math.floor(diff / 86400);

        let isValidDate =
          Object.prototype.toString.call(date) === "[object Date]" &&
          !isNaN(date.getTime());

        if (!isValidDate) {
          window.console.error("不是有效日期格式");
        }
        const formatDate = function(date) {
          let today = new Date(date);
          let year = today.getFullYear();
          let month = ("0" + (today.getMonth() + 1)).slice(-2);
          let day = ("0" + today.getDate()).slice(-2);
          let hour = today.getHours();
          let minute = today.getMinutes();
          let second = today.getSeconds();
          return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
        };

        if (isNaN(dayDiff) || dayDiff < 0 || dayDiff >= 31) {
          return formatDate(date);
        }
        return (
          (dayDiff === 0 &&
            ((diff < 60 && "刚刚") ||
              (diff < 120 && "1分钟前") ||
              (diff < 3600 && Math.floor(diff / 60) + "分钟前") ||
              (diff < 7200 && "1小时前") ||
              (diff < 86400 && Math.floor(diff / 3600) + "小时前"))) ||
          (dayDiff === 1 && "昨天") ||
          (dayDiff < 7 && dayDiff + "天前") ||
          (dayDiff < 31 && Math.ceil(dayDiff / 7) + "周前")
        );
      },
    }
  }
</script>
<style lang="less" scoped>
.ss-tui{
  position: absolute;
  top:0;
  right: 0.25rem;;
  color: #f9c542;
  font-size: 0.36rem;
}
  .hot-header{
    position: relative;
    display: flex;
    align-items: center;
    background: #ffffff;
    padding: 0.3rem 0.3rem 0 0.2rem;
    .pendant{
      width: 100%;
      height: 100%;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      border-radius: 100%;
    }
    .pendant-container{
      width: 0.9rem;
      position: relative;
      height: 0.9rem;
    }
  }
  .avatar{
    width: 0.7rem;
    height: 0.7rem;
    border-radius: 0.35rem;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
  .header-right{
    margin-left: 0.1rem;
    width: 6rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .nameleft{
    display: flex;
    flex-direction: column;
  }
  .name{
    font-family: PingFangSC-Medium, sans-serif;
    font-size: 0.3rem;
    color: #494949;
    font-weight: bold;
  }
  .discusstime{
    display: inline-block;
  }
  .hot-discuss-time{
    font-family: PingFangSC-Regular, sans-serif;
    font-size: 0.22rem;
    color: #999999;
  }
  .hot-shuoshuo-time{
    font-size: 0.22rem;
    font-family: PingFangSC-Regular, sans-serif;
    color: #999999;
    text-align: left;
  }
  .hot-shuoshuo{
    font-family: PingFangSC-Regular, sans-serif;
    font-size: 0.22rem;
    color: #999999;
    display: flex;
    align-items: center;
    max-width: 200px;
  }
</style>
